<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $table = 'ims_yh_category';
    
    protected $guarded = [];
    
    public $timestamps = false;
    
    /**
     * 获取子分类
     */
    public function children()
    {
        return $this->hasMany(Category::class, 'parent_id', 'id')
            ->where('deleted_at', 0)
            ->orderBy('display_order', 'asc');
    }
    
    /**
     * 获取父分类
     */
    public function parent()
    {
        return $this->belongsTo(Category::class, 'parent_id', 'id');
    }
}

